-
Notifications
You must be signed in to change notification settings - Fork 372
chore(clerk-js,types): Update checkout flow to support free trials #6494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(clerk-js,types): Update checkout flow to support free trials #6494
Conversation
🦋 Changeset detectedLatest commit: 972b353 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 WalkthroughWalkthroughAdds free-trial support across the codebase. Introduces CommerceCheckout.freeTrialEndsAt (Date | null) parsed from JSON and exposed via useCheckout fallback and types. UI updates: CheckoutForm and CheckoutComplete display free-trial badges, trial end date, and a “total due after trial” line; submit button text is centralized via useSubmitLabel. SubscriptionBadge accepts a 'free_trial' status. CommerceSubscription defaults eligibleForFreeTrial to false. Title component accepts an optional badge. Many localization files and tests were updated to cover free-trial flows. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 11
🧹 Nitpick comments (12)
.changeset/sour-lemons-talk.md (1)
6-6
: Consider a more descriptive summary for release notes.
E.g., “Add free trial fields to CommerceCheckout and related resources; wire into UI and localization.”.changeset/tender-planets-win.md (1)
7-7
: Nit: Expand the message for clarity.
E.g., “PricingTable: show trial footer notice and date when free trials are enabled; add localization keys.”packages/clerk-js/src/core/resources/CommerceCheckout.ts (1)
26-26
: Document new public property with JSDoc.
Add succinct JSDoc forfreeTrialEndsAt
to clarify source and timezone.Apply:
export class CommerceCheckout extends BaseResource implements CommerceCheckoutResource { @@ - freeTrialEndsAt!: Date | null; + /** + * End date of the free trial for this checkout, or null if not on trial. + * Derived from API field `free_trial_ends_at` (unix epoch seconds) and converted to a JS Date in UTC. + */ + freeTrialEndsAt!: Date | null;packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (1)
238-244
: Localization key selection is correct; minor tidy and tests suggested.
- Redundant optional chaining on
subscription
inside a guarded branch; optional.- Please add tests covering footer behavior for: upcoming, active with trial in future, active with trial in past, and active with period mismatch.
I can draft component tests (React Testing Library) for these scenarios if helpful.
packages/clerk-js/src/core/resources/CommercePlan.ts (2)
30-31
: Public API docs for new fields.Add JSDoc on the new properties to keep the public API self-documented and discoverable.
export class CommercePlan extends BaseResource implements CommercePlanResource { ... - freeTrialDays!: number | null; - freeTrialEnabled!: boolean; + /** Number of free trial days for this plan; null when no trial is configured. */ + freeTrialDays!: number | null; + /** Whether free trials are enabled for this plan. */ + freeTrialEnabled!: boolean;
33-36
: Tests missing for new fields.No tests were provided for mapping free trial fields from JSON and snapshot parity. Please add minimal unit tests covering:
- fromJSON sets freeTrialDays/freeTrialEnabled defaults and values.
- __internal_toSnapshot includes these fields (when you add them).
packages/clerk-js/src/core/resources/CommerceSubscription.ts (1)
81-85
: Tests recommended for free trial mapping and date conversion.Add tests verifying:
- eligibleForFreeTrial default/value mapping.
- freeTrialEndsAt date conversion with undefined/null present.
- Stability of behavior when JSON omits experimental fields.
Also applies to: 86-113
packages/types/src/json.ts (3)
785-788
: Remove commented-out schema line.Avoid commented schema fields in published types.
- // is_free_trial: boolean; // TODO(@COMMERCE): Remove optional after GA. free_trial_ends_at?: number | null;
817-818
: Subscription JSON addition approved; mark experimental for clarity.Consider annotating with an inline JSDoc to match surrounding experimental notes.
export interface CommerceSubscriptionJSON extends ClerkResourceJSON { ... - eligible_for_free_trial?: boolean; + /** @experimental */ + eligible_for_free_trial?: boolean;
882-884
: Checkout JSON addition approved; keep GA note, add JSDoc.Matches the item JSON pattern.
export interface CommerceCheckoutJSON extends ClerkResourceJSON { ... - // TODO(@COMMERCE): Remove optional after GA. - free_trial_ends_at?: number | null; + // TODO(@COMMERCE): Remove optional after GA. + /** @experimental */ + free_trial_ends_at?: number | null;packages/clerk-js/src/ui/components/Subscriptions/badge.tsx (1)
31-37
: Stale@ts-expect-error
commentThe comment still mentions “
ended
is included” while the suppressed key is now"free_trial"
.
Refresh the comment (or delete it once the enum is fixed) to avoid confusion.packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx (1)
56-60
: Minor – avoid rendering empty badge container
SubscriptionBadge
is rendered inside the JSX conditional, but the parent passesnull
when the condition fails, leaving an unnecessarybadge={null}
prop.-badge={ - plan.freeTrialEnabled && freeTrialEndsAt ? ( - <SubscriptionBadge subscription={{ status: 'free_trial' }} /> - ) : null -} +badge={ + plan.freeTrialEnabled && freeTrialEndsAt + ? <SubscriptionBadge subscription={{ status: 'free_trial' }} /> + : undefined +}Passing
undefined
spares React a noop render.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (15)
.changeset/sour-lemons-talk.md
(1 hunks).changeset/tender-planets-win.md
(1 hunks)packages/clerk-js/src/core/resources/CommerceCheckout.ts
(3 hunks)packages/clerk-js/src/core/resources/CommercePlan.ts
(2 hunks)packages/clerk-js/src/core/resources/CommerceSubscription.ts
(4 hunks)packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
(10 hunks)packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
(2 hunks)packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
(1 hunks)packages/clerk-js/src/ui/contexts/components/Plans.tsx
(4 hunks)packages/clerk-js/src/ui/elements/LineItems.tsx
(2 hunks)packages/localizations/src/en-US.ts
(4 hunks)packages/shared/src/react/hooks/useCheckout.ts
(1 hunks)packages/types/src/commerce.ts
(4 hunks)packages/types/src/json.ts
(4 hunks)packages/types/src/localization.ts
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (13)
.changeset/**
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/tender-planets-win.md
.changeset/sour-lemons-talk.md
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/shared/src/react/hooks/useCheckout.ts
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/core/resources/CommerceCheckout.ts
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/types/src/commerce.ts
packages/types/src/localization.ts
packages/localizations/src/en-US.ts
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/shared/src/react/hooks/useCheckout.ts
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/core/resources/CommerceCheckout.ts
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/types/src/commerce.ts
packages/types/src/localization.ts
packages/localizations/src/en-US.ts
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/shared/src/react/hooks/useCheckout.ts
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/core/resources/CommerceCheckout.ts
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/types/src/commerce.ts
packages/types/src/localization.ts
packages/localizations/src/en-US.ts
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/shared/src/react/hooks/useCheckout.ts
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/core/resources/CommerceCheckout.ts
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/types/src/commerce.ts
packages/types/src/localization.ts
packages/localizations/src/en-US.ts
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/shared/src/react/hooks/useCheckout.ts
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/core/resources/CommerceCheckout.ts
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/types/src/commerce.ts
packages/types/src/localization.ts
packages/localizations/src/en-US.ts
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/shared/src/react/hooks/useCheckout.ts
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/core/resources/CommerceCheckout.ts
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/types/src/commerce.ts
packages/types/src/localization.ts
packages/localizations/src/en-US.ts
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
**/*
⚙️ CodeRabbit Configuration File
If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.
Files:
packages/shared/src/react/hooks/useCheckout.ts
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/core/resources/CommerceCheckout.ts
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/types/src/commerce.ts
packages/types/src/localization.ts
packages/localizations/src/en-US.ts
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}
: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure
Files:
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
**/*.{jsx,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{jsx,tsx}
: Use error boundaries in React components
Minimize re-renders in React components
**/*.{jsx,tsx}
: Always use functional components with hooks instead of class components
Follow PascalCase naming for components:UserProfile
,NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...
Files:
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
**/*.tsx
📄 CodeRabbit Inference Engine (.cursor/rules/react.mdc)
**/*.tsx
: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering
Files:
packages/clerk-js/src/ui/elements/LineItems.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/localizations/**/*
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Localization files must be placed in 'packages/localizations/'.
Files:
packages/localizations/src/en-US.ts
**/localizations/**/*.ts
⚙️ CodeRabbit Configuration File
**/localizations/**/*.ts
: Review the changes to localization files with the following guidelines:
- Ensure that no existing translations are accidentally removed unless they are being replaced or fixed. If a string is removed, verify that it is intentional and justified.
- Check that all translations are friendly, formal, or semi-formal. Explicit, offensive, or inappropriate language is not allowed. If you find any potentially offensive language or are unsure, tag the @clerk/sdk-infra team in a separate comment. If you do not intend to tag the team, refer to it as "Clerk SDK Infra team" instead.
- Use the most up-to-date base localization file (https://github.com/clerk/javascript/blob/main/packages/localizations/src/en-US.ts) to validate changes, ensuring consistency and completeness.
- Confirm that new translations are accurate, contextually appropriate, and match the intent of the original English strings.
- Check for formatting issues, such as missing placeholders, incorrect variable usage, or syntax errors.
- Ensure that all keys are unique and that there are no duplicate or conflicting entries.
- If you notice missing translations for new keys, flag them for completion.
Files:
packages/localizations/src/en-US.ts
🧠 Learnings (1)
📚 Learning: 2025-07-22T08:43:52.095Z
Learnt from: panteliselef
PR: clerk/javascript#6317
File: packages/clerk-js/src/ui/contexts/components/Plans.tsx:56-68
Timestamp: 2025-07-22T08:43:52.095Z
Learning: The `useSubscription` hook exported from `packages/clerk-js/src/ui/contexts/components/Plans.tsx` is only used internally within clerk-js UI components and is not exposed to external consumers, making renames and modifications to this hook non-breaking for end users.
Applied to files:
packages/clerk-js/src/ui/contexts/components/Plans.tsx
🧬 Code Graph Analysis (2)
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx (1)
packages/types/src/commerce.ts (1)
CommerceSubscriptionItemResource
(994-1146)
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (1)
packages/clerk-js/src/ui/localization/localizationKeys.ts (1)
localizationKeys
(72-77)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (8)
.changeset/sour-lemons-talk.md (1)
1-4
: Changeset frontmatter looks correct for a minor bump.
No structural issues detected..changeset/tender-planets-win.md (1)
1-5
: Minor bumps are appropriate for these packages.
Scope aligns with UI + types + localization updates.packages/clerk-js/src/core/resources/CommerceCheckout.ts (2)
10-11
: Import for date conversion is appropriate.
Alias usage matches other parts of the repo; no issues.
49-49
: Approve mapping and types
All checks passed—free_trial_ends_at
is defined onCommerceCheckoutJSON
andfreeTrialEndsAt: Date | null
exists onCommerceCheckoutResource
. The conversion viaunixEpochToDate
mirrors the pattern inCommerceSubscription
. No changes required.packages/types/src/localization.ts (1)
146-146
: All new localization keys are present and correctly parameterized
- Verified that packages/localizations/src/en-US.ts defines:
- badge__freeTrial
- badge__trialEndsAt (uses
{{ date }}
)- startFreeTrial
- startFreeTrial__days (uses
{{ days }}
)- totalDueAfterTrial (uses
{{ days }}
)- Confirmed types in packages/types/src/localization.ts match:
- badge__trialEndsAt:
LocalizationValue<'date'>
- startFreeTrial__days:
LocalizationValue<'days'>
- totalDueAfterTrial:
LocalizationValue<'days'>
- Call sites supply the correct params (
date
for trialEndsAt,days
for days-based keys).No further changes needed.
packages/types/src/json.ts (2)
652-654
: All new JSON fields are consumed.
Verified thatfree_trial_days
,free_trial_enabled
,eligible_for_free_trial
, andfree_trial_ends_at
are referenced in both core resources and all relevant UI components—no further action needed.
652-654
: Resource mapping confirmed for new optional JSON fieldsThe
free_trial_days
andfree_trial_enabled
properties are correctly handled inCommercePlan
:
- packages/clerk-js/src/core/resources/CommercePlan.ts:
• Line 61:this.freeTrialDays = this.withDefault(data.free_trial_days, null);
• Line 62:this.freeTrialEnabled = this.withDefault(data.free_trial_enabled, false);
No further changes needed.
packages/localizations/src/en-US.ts (1)
43-48
: Localization keys look good – remember to add translations for other localesNew keys and placeholders are syntactically correct and non-duplicated.
Ensure equivalent entries are added to every supported locale before release.Also applies to: 92-93, 148-150
…-plan-card-with-free-trial-info-status # Conflicts: # packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
…with-free-trial-info-status # Conflicts: # packages/clerk-js/src/core/resources/CommerceSubscription.ts # packages/types/src/json.ts
…w-to-support-free-trials # Conflicts: # packages/clerk-js/src/core/resources/CommerceSubscription.ts # packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx # packages/types/src/commerce.ts # packages/types/src/json.ts
…rial-info-status' into elef/com-1123-update-checkout-flow-to-support-free-trials # Conflicts: # packages/clerk-js/src/core/resources/CommerceSubscription.ts # packages/clerk-js/src/ui/contexts/components/Plans.tsx # packages/localizations/src/en-US.ts
…t-free-trials # Conflicts: # packages/clerk-js/src/ui/contexts/components/Plans.tsx # packages/types/src/localization.ts
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
.changeset/rotten-lines-cough.md (2)
9-9
: Fix markdown list indentation (MD007) and readabilityThe bullet is indented by two spaces, violating markdownlint MD007 and potentially rendering inconsistently. Remove the leading spaces (and optionally add a blank line before the list).
Apply:
- - Added `freeTrialEndsAt` property to `CommerceCheckoutResource` interface. +- Added `freeTrialEndsAt` property to `CommerceCheckoutResource` interface.Optional readability tweak (blank line before list):
-Add support for trials in `<Checkout/>` +Add support for trials in `<Checkout/>` + - - Added `freeTrialEndsAt` property to `CommerceCheckoutResource` interface. +- Added `freeTrialEndsAt` property to `CommerceCheckoutResource` interface.
8-10
: Enrich the changeset summary to reflect key user-facing updatesConsider expanding the summary bullets so release notes capture the breadth of the change (UI copy, badges, submit label, and locale keys). This helps consumers understand the impact without scanning the PR.
Suggested additions:
Add support for trials in `<Checkout/>` - Added `freeTrialEndsAt` property to `CommerceCheckoutResource` interface. + - `CommerceCheckout` maps `free_trial_ends_at` → `freeTrialEndsAt` (Date | null). + - `<CheckoutForm/>` and `<CheckoutComplete/>` display trial status and end date; submit label accounts for trials. + - `SubscriptionBadge` supports `free_trial` status. + - Localization: adds keys like `badge__freeTrial`, `lineItems.title__freeTrialEndsAt`, `title__trialSuccess`, `totalDueAfterTrial`, `startFreeTrial__days`.packages/clerk-js/bundlewatch.config.json (2)
3-3
: Avoid brittle budgets; add small, intentional headroom for clerk.jsA +0.1KB bump (≈102 bytes) is extremely tight and may cause flaky CI due to minor, non-functional diffs (e.g., dependency patch updates, banner changes). Either optimize to stay within 622KB or add a modest buffer to reduce churn.
Recommended change:
- { "path": "./dist/clerk.js", "maxSize": "622.1KB" }, + { "path": "./dist/clerk.js", "maxSize": "623KB" },Optional: If you want more stable and user-centric constraints, consider measuring compressed size globally (gzip or brotli) in bundlewatch:
{ "compression": "brotli" }Please confirm whether you prefer to keep strict raw size budgeting or switch to compressed size budgeting going forward.
26-26
: Right-size the checkout bundle budget to reduce repeated nudgesThe 8.75KB cap is quite precise and likely to trigger frequent PR updates as free-trial UI evolves. Provide a small buffer to avoid CI churn while still guarding against regressions.
Recommended change:
- { "path": "./dist/checkout*.js", "maxSize": "8.75KB" }, + { "path": "./dist/checkout*.js", "maxSize": "9KB" },If you keep the tighter limit, ensure the current delta is intentional (new strings/UI for free-trials) and not due to accidental imports.
packages/clerk-js/jest.setup.ts (1)
36-55
: Align IntersectionObserver mock with the Web API and use globalThis consistently
- Use globalThis (you already do above) instead of global for consistency.
- The real API methods are void; returning null is misleading. Also, takeRecords should return an array.
Apply this diff:
- //@ts-expect-error - JSDOM doesn't provide IntersectionObserver, so we mock it for testing - global.IntersectionObserver = class IntersectionObserver { + //@ts-expect-error - JSDOM doesn't provide IntersectionObserver, so we mock it for testing + globalThis.IntersectionObserver = class IntersectionObserver { constructor() {} disconnect() { - return null; + // no-op } observe() { - return null; + // no-op } takeRecords() { - return null; + return []; } unobserve() { - return null; + // no-op } };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.changeset/rotten-lines-cough.md
(1 hunks)packages/clerk-js/bundlewatch.config.json
(2 hunks)packages/clerk-js/jest.setup.ts
(2 hunks)packages/clerk-js/src/ui/components/Checkout/__tests__/Checkout.test.tsx
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/clerk-js/src/ui/components/Checkout/tests/Checkout.test.tsx
🧰 Additional context used
📓 Path-based instructions (8)
.changeset/**
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/rotten-lines-cough.md
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/bundlewatch.config.json
packages/clerk-js/jest.setup.ts
**/*
⚙️ CodeRabbit Configuration File
If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.
Files:
packages/clerk-js/bundlewatch.config.json
packages/clerk-js/jest.setup.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/jest.setup.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/jest.setup.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/jest.setup.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/jest.setup.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/jest.setup.ts
🪛 markdownlint-cli2 (0.17.2)
.changeset/rotten-lines-cough.md
9-9: Unordered list indentation
Expected: 0; Actual: 2
(MD007, ul-indent)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Static analysis
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
.changeset/rotten-lines-cough.md (1)
2-6
: Package selection and version bumps look appropriateMinor bumps for @clerk/localizations, @clerk/clerk-js, @clerk/shared, and @clerk/types align with adding free-trial support and new type surface without breaking changes.
…t-free-trials # Conflicts: # packages/localizations/src/fa-IR.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🔭 Outside diff range comments (3)
packages/localizations/src/fa-IR.ts (3)
98-103
: Add translation for checkout lineItems.title__freeTrialEndsAt.This label is visible in the checkout summary; it shouldn't fall back to English.
Apply this diff:
- title__freeTrialEndsAt: undefined, + title__freeTrialEndsAt: 'پایان آزمایش رایگان',
319-321
: Complete missing subscription table headers under Organization Billing.These are visible headers; align with existing userProfile translations for consistency.
Apply this diff:
- tableHeader__edit: undefined, - tableHeader__plan: undefined, - tableHeader__startDate: undefined, + tableHeader__edit: 'ویرایش', + tableHeader__plan: 'طرح', + tableHeader__startDate: 'تاریخ شروع',
87-111
: Add missing Persian translations for new localization keysThe following keys exist in en-US but are still
undefined
in packages/localizations/src/fa-IR.ts. Please supply appropriate Persian strings that match the English meaning:
- badge__freeTrial (currently undefined at line 58)
- title__freeTrialEndsAt (line 98)
- title__trialSuccess (line 109)
- totalDueAfterTrial (line 110)
- startFreeTrial (line 146)
Note: startFreeTrial__days is already translated. Ensure your new entries align with:
• badge__freeTrial: “Free trial”
• title__freeTrialEndsAt: “Trial ends on”
• title__trialSuccess: “Trial successfully started!”
• totalDueAfterTrial: “Total Due after trial ends in {{days}} days”
• startFreeTrial: “Start free trial”
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/localizations/src/fa-IR.ts
(4 hunks)packages/localizations/src/pt-BR.ts
(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/localizations/src/pt-BR.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/localizations/src/fa-IR.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/localizations/src/fa-IR.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/localizations/src/fa-IR.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/localizations/src/fa-IR.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/localizations/src/fa-IR.ts
packages/localizations/**/*
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Localization files must be placed in 'packages/localizations/'.
Files:
packages/localizations/src/fa-IR.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/localizations/src/fa-IR.ts
**/*
⚙️ CodeRabbit Configuration File
If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.
Files:
packages/localizations/src/fa-IR.ts
**/localizations/**/*.ts
⚙️ CodeRabbit Configuration File
**/localizations/**/*.ts
: Review the changes to localization files with the following guidelines:
- Ensure that no existing translations are accidentally removed unless they are being replaced or fixed. If a string is removed, verify that it is intentional and justified.
- Check that all translations are friendly, formal, or semi-formal. Explicit, offensive, or inappropriate language is not allowed. If you find any potentially offensive language or are unsure, tag the @clerk/sdk-infra team in a separate comment. If you do not intend to tag the team, refer to it as "Clerk SDK Infra team" instead.
- Use the most up-to-date base localization file (https://github.com/clerk/javascript/blob/main/packages/localizations/src/en-US.ts) to validate changes, ensuring consistency and completeness.
- Confirm that new translations are accurate, contextually appropriate, and match the intent of the original English strings.
- Check for formatting issues, such as missing placeholders, incorrect variable usage, or syntax errors.
- Ensure that all keys are unique and that there are no duplicate or conflicting entries.
- If you notice missing translations for new keys, flag them for completion.
Files:
packages/localizations/src/fa-IR.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
Description
On confirmation
On completed
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
New Features
Localization
Tests